package com.xl.yygh.oss.controller;

import com.xl.yygh.common.result.Result;
import com.xl.yygh.oss.service.FileService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author XiangLiang
 * @date 2023/11/10 9:42
 * @description
 */
@RestController
@RequestMapping("/api/oss/file")
public class FileApiController {
    @Resource
    private FileService fileService;

    /**
     * 上传文件到阿里云oss
     *
     * @param file 上传的文件
     * @return 上传文件的Url
     */
    @PostMapping("fileUpload")
    public Result fileUpload(MultipartFile file) {
        // 获取上传文件
        String url = fileService.upload(file);
        return Result.ok(url);
    }
}
